package com.yuexun.beilunpatient.ui.contractmanage.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.base.BaseKJActivity;
import com.yuexun.beilunpatient.config.AppConfig;
import com.yuexun.beilunpatient.ui.contractmanage.bean.VideoBean;
import com.yuexun.beilunpatient.ui.contractmanage.bean.VideoListBean;
import com.yuexun.beilunpatient.ui.contractmanage.model.impl.ContractManageModel;
import com.yuexun.beilunpatient.ui.contractmanage.presenter.impl.VideoPresenter;
import com.yuexun.beilunpatient.ui.contractmanage.ui.view.IVideoView;
import com.yuexun.beilunpatient.ui.main.ui.Act_Webview;
import com.yuexun.beilunpatient.ui.main.ui.Act_X5Webview;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2019/4/4 0004.
 */

public class Act_Video_Main extends BaseKJActivity implements IVideoView {

    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.tv_visitno)
    TextView tvVisitno;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.tv_judge)
    TextView tvJudge;

    VideoPresenter presenter;
    String uid,reportUrl="",imageUrl="";

    @Override
    public void setRootView() {
        setContentView(R.layout.act_video_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        presenter = new VideoPresenter(this,new ContractManageModel());
        uid = getIntent().getExtras().getString("uid");
        title.setText(getIntent().getExtras().getString("title"));
        tvVisitno.setText("门诊/住院号:"+getIntent().getExtras().getString("visitno"));
        tvTime.setText("检查时间:"+getIntent().getExtras().getString("time"));
        ApiGetDataDetail(uid);
    }

    /**
     * 请请求数据-云影像详情
     */
    private void ApiGetDataDetail(String observationUID) {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuidPatient", PreferenceHelper.readString(this, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("observationUID", observationUID);
        presenter.cIcheckInfo(params);
    }



    @OnClick({R.id.title_back, R.id.ll_report, R.id.ll_video})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                finish();
                break;
            case R.id.ll_report:
                if(reportUrl.length()>0)
                {
                    Intent intent = new Intent(this, Act_Webview.class);
                    intent.putExtra("url",reportUrl);
                    intent.putExtra("title","报告详情");
                    startActivity(intent);
                }
                else {
                    ViewInject.toast("报告不存在");
                }
                break;
            case R.id.ll_video:
                if(imageUrl.length()>0)
                {
                    Intent intent = new Intent(this, Act_X5Webview.class);
                    intent.putExtra("url",imageUrl);
                    intent.putExtra("title","影像详情");
                    startActivity(intent);
                }
                else {
                    ViewInject.toast("影像不存在");
                }
                break;
        }
    }

    @Override
    public void cIcheckList(VideoListBean videoListBean) {

    }

    @Override
    public void cIcheckInfo(VideoBean videoBean) {
        if(videoBean.getStatus().equals("200"))
        {
            tvContent.setText(videoBean.getDatas().get(0).getData().getStudyDescription());
            tvJudge.setText(videoBean.getDatas().get(0).getData().getDiagnosticImpression());
            reportUrl = videoBean.getDatas().get(0).getData().getRepetorViewUrl();
            imageUrl = videoBean.getDatas().get(0).getData().getImageViewUrl();
        }
        else {
            ViewInject.toast(videoBean.getMessage());
        }
    }

    @Override
    public void dismiss() {

    }
}
